package demo1;

public class text {
}

    @Override
    public void addLast(int data) {
        Mylistnode node = new Mylistnode(data);

        if(hand == NULL) {
            hand = node;
            return;
        }
        listnode cur = hand;
        while(cur.next != NNLL) {
            cur = cur.next;

        }
        cur =  node;

    }
    @Override
    public void display() {
    ListNode cur  = head;
    while(cur != null && cur.next != null) {
        System.out.println(cur.val);
        cur = cur.next;
        }
    }
    @Override
    public int size() {
    int ret = 0;
        ListNode cur  = head;

        while(cur != null &&cur.next != null) {
        cur = cur.next;
        ret++;
    }
        return ret;
    }
    @Override
    public boolean contains(int key) {
        ListNode cur  = head;

        while(cur != null &&cur.next != null) {
            if(cur.val == key){
                return true;
            }
        }
        return false；
    }

    public void addIndex(int index, int data) {
        int len = size();
        if(index < 0 || index > len) {
            return;
        }
        if(index == 0) {
            addFirst(data);
            return;
        }

        if(index == len) {
            addLast(data);
            return;
        }
        class Solution {
            public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
                ListNode one = new ListNode(0);
                ListNode two = one;
                while(list1 != null && list2 != null) {
                    if(list1.val <= list2.val) {
                        two.next = list1;
                        list1 = list1.next;
                    } else {
                        two.next = list2;
                        list2 = list2.next;
                    }
                    two = two.next;
                }
                two.next = list1 == null ? list2 : list1;
                return one.next;
            }
        }
    }
    public void claer {
        ListNode cur = head;
        while(cur != null) {
        ListNode curn = cur.next;
            cur.next = null;
            cur.prev = null;
            cur = curn;
        }
        head = last = null;
    }
public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[10];
    }

    public void push(int val) {
        if(isFull()) {
            this.elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++] = val;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }

    public int pop() {

    }
    //获取栈顶元素 但是不删除
    public int peek() {

    }

    public boolean isEmpty() {

    }
    // 1、无头单向非循环链表实现
    public class SingleLinkedList {
        //头插法
        public void addFirst(int date) {
            ListNode cur = new ListNode(date);

        }
        //尾插法
        public void addLast(int data);
        //任意位置插入,第一个数据节点为0号下标
        public boolean addIndex(int index,int data);
        //查找是否包含关键字key是否在单链表当中
        public boolean contains(int key){
            ListNode cur = head;
            while(cur != null) {
                if(cur.val == key) {
                    return true;
                }
                cur = cur.next;
            }
            return false;
        }
        //删除第一次出现关键字为key的节点
        public void remove(int key);
        //删除所有值为key的节点
        public void removeAllKey(int key);
        //得到单链表的长度
        public int size() {
            int a = 10;
        }
        public void display();
        public void clear();
    }
    // 1、无头单向非循环链表实现
    public class SingleLinkedList {
        //头插法
        public void addFirst(int date) {
            ListNode cur = new ListNode(date);

        }
        //尾插法
        public void addLast(int data);
        //任意位置插入,第一个数据节点为0号下标
        public boolean addIndex(int index,int data);
        //查找是否包含关键字key是否在单链表当中
        public boolean contains(int key){
            ListNode cur = head;
            while(cur != null) {
                if(cur.val == key) {
                    return true;
                }
                cur = cur.next;
            }
            return false;
        }
        //删除第一次出现关键字为key的节点
        public void remove(int key);
        //删除所有值为key的节点
        public void removeAllKey(int key);
        //得到单链表的长度
        public int size() {
            int a = 10;
        }
        public void display();
        public void clear();
    }
}class Solution {
            public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
                ListNode one = new ListNode(0);
                ListNode two = one;
                while(list1 != null && list2 != null) {
                    if(list1.val <= list2.val) {
                        two.next = list1;
                        list1 = list1.next;
                    } else {
                        two.next = list2;
                        list2 = list2.next;
                    }
                    two = two.next;
                }
                two.next = list1 == null ? list2 : list1;
                return one.next;
            }
        }
    }
